package com.love.marriage.offlineServiceProvider.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.love.marriage.common.interfaces.avoid.AvoidRepeatableCommit;
import com.love.marriage.common.interfaces.avoid.LogRestRequest;
import com.love.marriage.common.validator.Insert;
import com.love.marriage.common.validator.Update;
import com.love.marriage.common.vo.Result;
import com.love.marriage.common.vo.ResultBoolean;
import com.love.marriage.offlineServiceProvider.service.OfflineServiceProviderService;
import com.love.marriage.offlineServiceProvider.vo.OfflineServiceProviderVo;
import com.love.marriage.offlineServiceProvider.vo.ResultOfflineServiceProviderVo;
import com.love.marriage.offlineServiceProvider.vo.ResultOfflineServiceProviderVoPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * description:  线下服务商表restApi
 * author:       alex
 * createDate:   2024-12-08 12:08:27
 * version:      1.0.0
 */
@ApiSort(105)
@Tag(name = "线下服务商表相关接口", description = "线下服务商表相关接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("/offline-service-provider")
public class OfflineServiceProviderController {

    private final OfflineServiceProviderService offlineServiceProviderService;

    @ApiOperationSupport(order = 10, author = "alex")
    @Operation(summary = "获取线下服务商表分页", description = "获取线下服务商表分页")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultOfflineServiceProviderVoPage.class
                    )))
    @PostMapping(value = "/page")
    @Parameters({
            @Parameter(name = "pageNum", description = "页码", required = false),
            @Parameter(name = "pageSize", description = "每页大小", required = false)
    })
    public Result<Page<OfflineServiceProviderVo>> getPage(@RequestParam(value = "pageNum", required = false) Long pageNum,
                                                          @RequestParam(value = "pageSize", required = false) Long pageSize,
                                                          @RequestBody(required = false) OfflineServiceProviderVo offlineServiceProviderVo) {
        return Result.success(offlineServiceProviderService.getPage(pageNum, pageSize, offlineServiceProviderVo));
    }

    @ApiOperationSupport(order = 20, author = "alex")
    @Operation(summary = "获取线下服务商表详情", description = "获取线下服务商表详情")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultOfflineServiceProviderVo.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1"))
    })
    @GetMapping
    public Result<OfflineServiceProviderVo> query(@RequestParam(value = "id") Long id) {
        return Result.success(offlineServiceProviderService.queryOfflineServiceProvider(id));
    }

    @ApiOperationSupport(order = 25, author = "alex")
    @Operation(summary = "根据id获取线下服务商表详情(前端)", description = "根据id获取线下服务商表详情(前端)")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultOfflineServiceProviderVo.class
                    )))
    @Parameters({
            @Parameter(name = "userId", description = "用户id", required = true, schema = @Schema(implementation = Long.class, type = "Long", example = "1")),
            @Parameter(name = "type", description = "类型（emotion: 情感商学院,partner:合伙人）", required = true, schema = @Schema(implementation = String.class, type = "String", example = "emotion"))
    })
    @GetMapping(value = "queryByUserId")
    public Result<OfflineServiceProviderVo> queryByUserId(@RequestParam(value = "userId") Long userId,
                                                          @RequestParam(value = "type") String type) {
        return Result.success(offlineServiceProviderService.queryOfflineServiceProviderByUserId(userId, type));
    }

    @LogRestRequest(apiName = "添加线下服务商(前端)")
    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 28, author = "alex")
    @Operation(summary = "添加线下服务商(前端)", description = "添加线下服务商(前端)",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = OfflineServiceProviderVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultOfflineServiceProviderVo.class)))
    @PostMapping(value = "addInfo")
    public Result<OfflineServiceProviderVo> addInfo(@Validated({Insert.class}) @RequestBody OfflineServiceProviderVo offlineServiceProviderVo) {
        return Result.success(offlineServiceProviderService.addOrUpdateInfo(offlineServiceProviderVo));
    }

    @LogRestRequest(apiName = "新增线下服务商表")
    @AvoidRepeatableCommit
    @ApiOperationSupport(order = 30, author = "alex")
    @Operation(summary = "新增线下服务商表", description = "新增线下服务商表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = OfflineServiceProviderVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultOfflineServiceProviderVo.class)))
    @PostMapping
    public Result<OfflineServiceProviderVo> add(@Validated({Insert.class}) @RequestBody OfflineServiceProviderVo offlineServiceProviderVo) {
        return Result.success(offlineServiceProviderService.addOfflineServiceProvider(offlineServiceProviderVo));
    }

    @LogRestRequest(apiName = "修改线下服务商表")
    @ApiOperationSupport(order = 40, author = "alex")
    @Operation(summary = "修改线下服务商表", description = "修改线下服务商表",
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    description = "查询条件",
                    required = false,
                    content = @Content(schema = @Schema(implementation = OfflineServiceProviderVo.class))
            ))
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultOfflineServiceProviderVo.class)))
    @PutMapping
    public Result<OfflineServiceProviderVo> update(@Validated({Update.class}) @RequestBody OfflineServiceProviderVo offlineServiceProviderVo) {
        return Result.success(offlineServiceProviderService.updateOfflineServiceProvider(offlineServiceProviderVo));
    }

    @LogRestRequest(apiName = "刪除线下服务商表")
    @ApiOperationSupport(order = 50, author = "alex")
    @Operation(summary = "刪除线下服务商表", description = "刪除线下服务商表")
    @Parameters({
            @Parameter(name = "ids", description = "ids,用，分割", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1,2"))
    })
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(schema = @Schema(implementation = ResultBoolean.class)))
    @DeleteMapping
    public Result<Boolean> delete(@RequestParam("ids") String ids) {
        return Result.success(offlineServiceProviderService.deleteOfflineServiceProvider(ids));
    }

    @LogRestRequest(apiName = "审核线下服务商")
    @ApiOperationSupport(order = 60, author = "alex")
    @Operation(summary = "审核线下服务商", description = "审核线下服务商")
    @ApiResponse(responseCode = "200", description = "Success",
            content = @Content(mediaType = "application/json",
                    schema = @Schema(implementation = ResultBoolean.class
                    )))
    @Parameters({
            @Parameter(name = "id", description = "id", required = true, schema = @Schema(implementation = String.class, type = "String", example = "1")),
            @Parameter(name = "status", description = "状态", required = true, schema = @Schema(implementation = Integer.class, type = "Integer", example = "2"))
    })
    @GetMapping(value = "approve")
    public Result<Boolean> queryByUserId(@RequestParam(value = "id") Long id,
                                         @RequestParam(value = "status") Integer status) {
        return Result.success(offlineServiceProviderService.approveOfflineServiceProvider(id, status));
    }
}
